//
//  XTCVisitorMessage.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/13.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XTCVisitorMessage.h"
#import "XXTool.h"

@interface XTCVisitorMessage ()

@property (nonatomic,strong) UIView *contentBackground;

@property (nonatomic,strong) UILabel *companyName;

@property(nonatomic,strong) UIImageView *head;

@property (nonatomic,strong) UILabel *appointmentTime;

@property (nonatomic,strong) UILabel *hall;

@property (nonatomic,strong) UILabel *appointmentStatus;

@end

@implementation XTCVisitorMessage
{
    CGFloat rightLabelWidth;
}
-(UIView*)contentBackground
{
    if (_contentBackground==nil)
    {
        _contentBackground = [[UIView alloc] init];
        _contentBackground.layer.shadowOpacity = 1;
        //_contentBackground.layer.shadowColor = [UIColor colorWithRed:214/255.0 green:215/255.0 blue:216/255.0 alpha:1.0].CGColor;
        _contentBackground.layer.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3].CGColor;
        _contentBackground.layer.shadowOffset = CGSizeMake(0,1);
        _contentBackground.layer.shadowRadius = 2;
        _contentBackground.layer.masksToBounds = NO;
        [self addSubview:_contentBackground];
    }
    return _contentBackground;
}

-(UIImageView*)head{
    if(_head == nil){
        _head=[[UIImageView alloc]init];
        [_contentBackground addSubview:_head];
    }
    return _head;
}

-(UILabel*)companyName
{
    if (_companyName==nil)
    {
        _companyName = [[UILabel alloc] init];
        _companyName.font = [XXTool systemFontOfSize:13];
        _companyName.numberOfLines = 0;
        [_contentBackground addSubview:_companyName];
        
    }
    return _companyName;
}

-(UILabel*)appointmentTime
{
    if (_appointmentTime==nil)
    {
        _appointmentTime = [[UILabel alloc] init];
        _appointmentTime.font = [XXTool systemFontOfSize:13];
        _appointmentTime.textColor = [UIColor colorWithRed:89/255.0 green:87/255.0 blue:87/255.0 alpha:1.0];
        [_contentBackground addSubview:_appointmentTime];
        
        
    }
    return _appointmentTime;
}

-(UILabel*)hall
{
    if (_hall==nil)
    {
        _hall = [[UILabel alloc] init];
        _hall.font = [XXTool systemFontOfSize:13];
        _hall.textColor = [UIColor colorWithRed:89/255.0 green:87/255.0 blue:87/255.0 alpha:1.0];
        _hall.textAlignment = NSTextAlignmentRight;
        [_contentBackground addSubview:_hall];
        
    }
    return _hall;
}

-(UILabel*)appointmentStatus
{
    if (_appointmentStatus==nil)
    {
        _appointmentStatus = [[UILabel alloc] init];
        _appointmentStatus.layer.borderColor = [XXTool colorWithProject].CGColor;
        _appointmentStatus.layer.borderWidth = 0.6f;
        _appointmentStatus.layer.cornerRadius = 5;
        _appointmentStatus.textAlignment = NSTextAlignmentCenter;
        _appointmentStatus.textColor = [XXTool colorWithProject];
        _appointmentStatus.font = [XXTool systemFontOfSize:14];
        [_contentBackground addSubview:_appointmentStatus];
        
    }
    return _appointmentStatus;
}

-(void)initParameter
{
    rightLabelWidth = 75;
}

-(void)initUI
{
    [self contentBackground];
    [self companyName];
    [self appointmentTime];
    [self hall];
    [self appointmentStatus];
}

-(void)refreshLayout:(CGRect)frame
{
    CGFloat cnWidth = frame.size.width-rightLabelWidth-20*2-10;
    
    _head.frame=CGRectMake(20, 23, 60, 60);
    
    _companyName.frame = CGRectMake(20
                                    , 23
                                    , cnWidth
                                    , [XXTool getTextHeightByText:_companyName.text
                                                             Font:_companyName.font
                                                            Width:cnWidth]);
    _appointmentTime.frame = CGRectMake(_companyName.frame.origin.x
                                            , _companyName.frame.size.height+_companyName.frame.origin.y+17
                                            , cnWidth
                                            , 15);
    _hall.frame = CGRectMake(_companyName.frame.size.width+_companyName.frame.origin.x+10
                                 , _companyName.frame.origin.y+3
                                 , rightLabelWidth
                                 , 15);
    
    _contentBackground.frame = CGRectMake(0
                                          , 0
                                          , frame.size.width
                                          , _companyName.frame.size.height+23*2+17+15);
    
    _appointmentStatus.frame = CGRectMake(_hall.frame.origin.x
                                              , _contentBackground.frame.size.height-30-23
                                              , rightLabelWidth
                                              , 30);
    
    _contentBackground.layer.shadowPath = [UIBezierPath bezierPathWithRect:_contentBackground.frame].CGPath;
}

-(void)setCellWithData:(XMLVisitorMessageModel *)temp
{
    _companyName.text = [NSString stringWithFormat:@"%@\n%@",temp.cpname_en,temp.cpname];
    
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",[XXTool stampToTimeWithoutYear:temp.order_time]]];
    
    _appointmentTime.attributedText = string;
    
    _hall.text = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"展馆", nil),temp.mapname];
    
    if ([temp.accept isEqualToString:@"0"]) //待定
    {
        _contentBackground.backgroundColor = [UIColor whiteColor];
        _appointmentStatus.text = NSLocalizedString(@"待接受", nil);
        _appointmentStatus.layer.borderColor = [XXTool colorWithProject].CGColor;
        _appointmentStatus.textColor = [XXTool colorWithProject];
    }
    else if ([temp.accept isEqualToString:@"2"]) //拒绝
    {
        _contentBackground.backgroundColor = [UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1.0];
        _appointmentStatus.text = NSLocalizedString(@"拒绝详情", nil);
        _appointmentStatus.layer.borderColor = [UIColor grayColor].CGColor;
        _appointmentStatus.textColor = [UIColor grayColor];
    }
    else if ([temp.accept isEqualToString:@"1"]) //已确定
    {
        _contentBackground.backgroundColor = [UIColor whiteColor];
        _appointmentStatus.text = NSLocalizedString(@"预约详情", nil);
        _appointmentStatus.layer.borderColor = [XXTool colorWithProject].CGColor;
        _appointmentStatus.textColor = [XXTool colorWithProject];
    }
    else if ([temp.accept isEqualToString:@"3"]) //已逾期
    {
        _contentBackground.backgroundColor = [UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1.0];
        _appointmentStatus.text = NSLocalizedString(@"已逾期", nil);
        _appointmentStatus.layer.borderColor = [UIColor grayColor].CGColor;
        _appointmentStatus.textColor = [UIColor grayColor];
    }
    [self refreshLayout:self.frame];
}

+(CGFloat)getHeightWithData:(XMLVisitorMessageModel *)temp
{
    return [XXTool getTextHeightByText:[NSString stringWithFormat:@"%@\n%@",temp.cpname_en,temp.cpname]
                                  Font:[XXTool systemFontOfSize:13]
                                 Width:[UIScreen mainScreen].bounds.size.width-75-20*2-10]+23*2+17+15+5;
    
}

@end
